//satellite环绕脚本所在节点

cc.Class({
    extends: cc.Component,

    properties: {
        satellite1:{
            default:null,
            type:cc.Node
        },
        satellite2:{
            default:null,
            type:cc.Node
        },
        satellite3:{
            default:null,
            type:cc.Node
        }
    },

    start () {
        this.node.zIndex = 10
        this.time = 0
        
    },
    updateSurroundPos(node,radius,phase,period){
        this.node.parent.insertChild(node)
        if(node){
            if(!radius){
                radius = Math.abs(this.node.x -node.x)
            }
            if(!phase){
                phase = 0
            }
            if(!period){
                period = 2
            }
            node.x = this.node.x + radius * Math.sin(this.time*2*3.1415926/period+phase)
            let zpos = Math.cos(this.time*2*3.1415926/period+phase)
            if(zpos<0){
                node.zIndex =this.node.zIndex - 3
            }else{
                node.zIndex =this.node.zIndex + 3
            }
            node.scaleX = (3 + zpos )/3 
            node.scaleY = (3 + zpos )/3
        }
    },

    update (dt) {
        this.time +=dt
        this.updateSurroundPos(this.satellite1,100,0)
        this.updateSurroundPos(this.satellite2,100,2/3*3.1415926)
        this.updateSurroundPos(this.satellite3,100,4/3*3.1415926)
    },
});
